package com.saunter.service;

import com.saunter.extendMapper.CompanyExtendMapper;
import com.saunter.mapper.CompanyMapper;
import com.saunter.model.Company;
import com.saunter.utils.exception.ExceptionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("CompanyService")
public class CompanyService {
    @Autowired
    private CompanyExtendMapper companyExtendMapper;
    @Resource
    private ExceptionManager exceptionManager;

    public Company getInfo() {
        return companyExtendMapper.getCompanyOne();
    }

    public int edit(Company company) {
        Integer company_id = company.getId();
        if(null == company_id) {
            Company old_company = this.getInfo();
            company_id = null != old_company ? old_company.getId() : null;
            company.setId(company_id);
        }
        if(null == company_id || null == companyExtendMapper.selectByPrimaryKey(company_id)) {
//            throw exceptionManager.create("Com001");
            return companyExtendMapper.insertSelective(company);
        }
        return companyExtendMapper.updateByPrimaryKeySelective(company);
    }
}
